package com.cskaoyan.app.controller;

import com.cskaoyan.app.bean.common.BasePageInfo;
import com.cskaoyan.app.bean.common.BaseRespVo;
import com.cskaoyan.app.bean.common.CommonData;
import com.cskaoyan.app.bean.po.MarketCoupon;
import com.cskaoyan.app.bean.po.MarketCouponUser;
import com.cskaoyan.app.service.AdminCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("admin/coupon")
public class AdminCouponController {

    @Autowired
    private AdminCouponService adminCouponService;

    @GetMapping("list")
    public Object list(BasePageInfo info, String name, Integer type, Integer status) {
        CommonData<MarketCoupon> data = adminCouponService.list(info, name, type, status);
        return BaseRespVo.ok(data);
    }

    @PostMapping("create")
    public Object create(@RequestBody MarketCoupon marketCoupon) {
        MarketCoupon data = adminCouponService.create(marketCoupon);
        return BaseRespVo.ok(data);
    }

    @PostMapping("update")
    public Object update(@RequestBody MarketCoupon marketCoupon) {
        MarketCoupon data = adminCouponService.update(marketCoupon);
        return BaseRespVo.ok(data);
    }

    @GetMapping("read")
    public Object read(Integer id) {
        MarketCoupon data = adminCouponService.read(id);
        return BaseRespVo.ok(data);
    }

    @GetMapping("listuser")
    public Object listUser(BasePageInfo info, Integer couponId, Integer status, Integer userId) {
        CommonData<MarketCouponUser> data = adminCouponService.listUser(info, couponId, status, userId);
        return BaseRespVo.ok(data);
    }

    @PostMapping("delete")
    public Object delete(@RequestBody MarketCoupon marketCoupon) {
        adminCouponService.delete(marketCoupon);
        return BaseRespVo.ok();
    }

}
